package yt.kpool.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import yt.kpool.R;
import yt.kpool.bean.BaseBean;
import yt.kpool.network.HttpUtils;
import yt.kpool.network.MyGson;
import yt.kpool.network.NetHelperNew;
import yt.kpool.util.ToastUtil;


/**
 * 删除分组
 * Created by Administrator on 2017/12/25.
 */

public class DelectGroupDialog extends Dialog {


    private LoadingDialog loadingDialog;
    private String content;

    private TextView tv_sure;
    private TextView tv_dis;
    private TextView tv_content;



    private Context context;
    private OnSuccessListener onSuccessListener;
    private int id;


    public DelectGroupDialog(Context context, String text, int id, OnSuccessListener onSuccessListener) {
        super(context, R.style.mydialog);
        this.context = context;
        content = text;
        this.id = id;

        this.onSuccessListener = onSuccessListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_delect_group);
        setCancelable(false);
        initView();
    }

    public void initView() {
        loadingDialog = new LoadingDialog(context, 0);
        tv_sure = findViewById(R.id.tv_sure);
        tv_dis = findViewById(R.id.tv_dis);

        tv_content = findViewById(R.id.tv_content);
        tv_content.setText("确定要删除分组 " + content + " 吗？");


        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                    addMinerGroup();



            }


        });
        tv_dis.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();

            }


        });

    }

    private void addMinerGroup() {


        loadingDialog.show();
        NetHelperNew.DeleteMinerGroup(id + "",new HttpUtils.HttpCallback() {
            @Override
            public void onSuccess(String data) {
                loadingDialog.dismiss();
                BaseBean minerBean = MyGson.getInstance().fromJson(data, BaseBean.class);


                if (minerBean.getType() == 1) {

                    dismiss();
                    ToastUtil.showToast(context, minerBean.getContent());

                } else {

                    ToastUtil.showToast(context, minerBean.getContent());
                }

            }

            @Override
            public void onError(String msg) {
                super.onError(msg);
                loadingDialog.dismiss();
                ToastUtil.showToast(context, msg);
            }
        });
        onSuccessListener.getResult();
    }

    //点击回调
    public interface OnSuccessListener {
        void getResult();

    }

}
